#ifndef _MSG_Q_SERVLET
#define _MSG_Q_SERVLET

#include "IServlet.h"

class MsgQClientServlet : public IServlet {
public:
    virtual void on(SERVLET_STATUS type,std::function<int(ISession *session,void*,int)> handler);
    virtual void request(const void *data,int len);
    virtual void start();
    virtual void wait();
    virtual void stop();
    virtual void onLoad(INode *node);
    virtual void onMessage(ISession *session,void* data,int size);
    virtual void onState(SERVLET_STATUS status,ISession * session,int code);
    virtual void recvthreadLogic(int mqid);
    virtual void onUnload();
private:
    int servermqid = 0;
    int clientmqid = 0;
    std::string _connection;
    void *_client = 0;
    std::map<int,std::vector<std::function<int(ISession *,void*,int)> > > msgidHandlers;
    bool isRun = true;
};

class MsgQServerServlet : public IServlet {
public:
    virtual void on(SERVLET_STATUS type,std::function<int(ISession *session,void*,int)> handler);
    virtual void request(const void *data,int len);
    virtual void start();
    virtual void wait();
    virtual void stop();
    virtual void onLoad(INode *node);
    virtual void onUnload();
    virtual void onMessage(ISession *session,void* data,int size);
    virtual void onState(SERVLET_STATUS status,ISession * session,int code);
    virtual void recvthreadLogic(int mqid);
private:
    std::string _connection;
    std::map<int,std::vector<std::function<int(ISession *,void*,int)> > > msgidHandlers;
    int servermqid = 0;
    std::map<int,int> pidWithChildIds;
    void* _thread;
    bool isRun = true;
};

 


#endif // _MSG_Q_SERVLET